<template>
  <div class="table-form">
    <el-row :gutter="10">
      <el-col :span="14">
        <span class="title"
          >表格{{ rows > 0 ? "(已选择" + rows + "条)" : "" }}</span
        >
        <el-table
          :data="tableData"
          @selection-change="selectColumn"
          border
          style="width: 100%"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column prop="name" label="姓名" width="180" />
          <el-table-column prop="age" label="年龄" width="180" />
          <el-table-column prop="address" label="地址" />
          <el-table-column prop="avg" label="头像">
            <template #default="scope"
              ><el-image v-if="scope.row.avg"></el-image>
              <el-icon color="black" size="25" v-else> <Baseball /></el-icon>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
      <el-col :span="10">
        <span class="title">表单</span>
        <el-form
          label-position="right"
          label-width="100px"
          :model="form"
          style="max-width: 460px"
        >
          <el-form-item label="姓名" prop="name">
            <el-input v-model="form.name"></el-input>
          </el-form-item>
          <el-form-item label="年龄" prop="age">
            <el-input-number
              label="2"
              controls-position="right"
              step-strictly
              :step="1"
              v-model="form.age"
            />
          </el-form-item>
          <el-form-item label="出生日期" prop="birth">
            <el-date-picker
              v-model="form.birth"
              type="date"
              placeholder="选择时间"
            />
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script >
import { Baseball } from "@element-plus/icons-vue";
import { reactive, ref } from "vue-demi";
export default {
  components: { Baseball },
  setup() {
    const tableData = ref(null);
    const rows = ref(0);
    tableData.value = [
      {
        name: "作者",
        age: parseInt(Math.random() * 100),
        address: "中国香港新界大埔镇泰亨村",
        avg: null,
      },
      {
        name: "刘德华",
        age: parseInt(Math.random() * 100),
        address: "贵州省遵义市凤冈县",
        avg: null,
      },
    ];
    // 多选行
    const form = ref({
      name: null,
      age: 0,
      birth: null,
    });
    function selectColumn(row) {
      rows.value = row.length;
    }
    return {
      tableData,
      selectColumn,
      rows,
      form,
    };
  },
};
</script>

<style scoped lang="scss">
.table-form {
  .title {
    width: 100%;
    display: block;
    font-weight: bold;
    text-align: center;
    font-size: 24px;
    font-family: "黑体";
    margin-top: 2px;
    margin-bottom: 10px;
  }
  width: 100%;
}
</style>